package zhuyun.code.launcheractivity.view.adapter

import android.content.Context
import android.view.View
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import zhuyun.code.launcheractivity.R
import zhuyun.code.launcheractivity.model.data.PostDynamicListData
import zhuyun.code.launcheractivity.utils.CommonUtils
import zhuyun.code.launcheractivity.utils.GlideUtil

/**
 * @author: Administrator
 * @date: 2021/12/7
 */
class FollowDynamicAdapter(val context: Context,val data:MutableList<PostDynamicListData>):BaseQuickAdapter<PostDynamicListData,BaseViewHolder>(R.layout.item_dynamic_image,data) {
    override fun convert(helper: BaseViewHolder, item: PostDynamicListData) {
        GlideUtil.displayEspImage(item.UserInfo.HeadUrl,helper.getView(R.id.iv_avatar),R.drawable.pic_touxiang_normal)
        helper.setText(R.id.tv_name,item.StarName)
        helper.setText(R.id.tv_time,CommonUtils.getStandardDate(item.Addtime))
        helper.setText(R.id.tv_comment,"${item.CommentNum}")
        helper.setText(R.id.tv_like,"${item.LikeNum}")
        helper.setText(R.id.tv_content,item.TxtContent)
        if(item.PutTypeId == 2) {//图片
            helper.setVisibility(R.id.rv, View.VISIBLE)
            helper.setVisibility(R.id.rl_video, View.GONE)
            val recyclerView = helper.getView<RecyclerView>(R.id.rv)
            val onePicAdapter = CircleOnePicAdapter(context,item.filelist.toMutableList())
            if(item.filelist.size == 1){
                recyclerView.layoutManager = LinearLayoutManager(context)
                recyclerView.adapter = onePicAdapter
            } else if(item.filelist.size == 4){
                recyclerView.layoutManager = GridLayoutManager(context,2)
                recyclerView.adapter = onePicAdapter
            } else {
                recyclerView.layoutManager = GridLayoutManager(context, 3)
                recyclerView.adapter = onePicAdapter
            }
        } else if(item.PutTypeId == 3){//视频
            helper.setVisibility(R.id.rv, View.GONE)
            helper.setVisibility(R.id.rl_video, View.VISIBLE)
            GlideUtil.displayEspImage(item.MainPicUrl,helper.getView(R.id.iv_video),R.mipmap.icon_default_200x200)
        }

    }
}